package com.maimang.platform.controller.monitor;

import com.maimang.platform.annotation.Log;
import com.maimang.platform.base.BaseController;
import com.maimang.platform.base.Result;
import com.maimang.platform.common.entity.SysLoginLog;
import com.maimang.platform.enums.BusinessType;
import com.maimang.platform.page.TableDataInfo;
import com.maimang.platform.common.service.SysLoginLogService;
import com.maimang.platform.common.utils.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Rocky
 * @version 1.0.0
 * @类名 SysLoginLogController
 * @描述 <br>系统访问日志</br>
 * @日期 2019-04-25 16:22
 * @email jintaozhao@qq.com
 */
@Controller
@RequestMapping("/monitor/loginlog")
public class SysLoginLogController extends BaseController {

	private String prefix = "monitor/loginlog";

	@Autowired
	private SysLoginLogService loginLogService;

	@RequiresPermissions("monitor:loginlog:view")
	@GetMapping()
	public String loginLog() {
		return prefix + "/loginlog";
	}

	@RequiresPermissions("monitor:loginlog:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysLoginLog loginlog) {
		startPage();
		List<SysLoginLog> list = loginLogService.selectLoginLogList(loginlog);
		return getDataTable(list);
	}

	@Log(title = "登录日志", businessType = BusinessType.EXPORT)
	@RequiresPermissions("monitor:loginlog:export")
	@PostMapping("/export")
	@ResponseBody
	public Result export(SysLoginLog loginlog) {
		List<SysLoginLog> list = loginLogService.selectLoginLogList(loginlog);
		ExcelUtil<SysLoginLog> util = new ExcelUtil<SysLoginLog>(SysLoginLog.class);
		return util.exportExcel(list, "登录日志");
	}

	@RequiresPermissions("monitor:loginlog:remove")
	@Log(title = "登录日志", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public Result remove(String ids) {
		return toResult(loginLogService.deleteLoginLogByIds(ids));
	}

	@RequiresPermissions("monitor:loginlog:remove")
	@Log(title = "登录日志", businessType = BusinessType.CLEAN)
	@PostMapping("/clean")
	@ResponseBody
	public Result clean() {
		loginLogService.cleanLoginLog();
		return success();
	}
}
